package com.chen.blue.controller.admin.system;


import com.chen.blue.domain.delete.system.DataScopeUserDeptDelete;
import com.chen.blue.domain.delete.system.UserRoleDelete;
import com.chen.blue.domain.dto.system.DataScopeUserDeptDto;
import com.chen.blue.domain.dto.system.UserRoleDto;
import com.chen.blue.domain.dto.system.update.DataScopeUserDeptDtoEdit;
import com.chen.blue.domain.dto.system.update.UserRoleDtoEdit;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IDataScopeUserDeptService;
import com.chen.blue.service.system.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-05-11
 */
@Api(tags = "用户部门模块")
@Validated
@RestController
@RequestMapping("/dept/user")
public class DataScopeUserDeptController {

    @Resource
    private IDataScopeUserDeptService iDataScopeUserDeptService;

    //    @ApiOperation(value = "用户部门添加", notes = "用户部门添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid List<DataScopeUserDeptDto> dataScopeUserDeptDtoList) throws DtoNullException {

        return iDataScopeUserDeptService.addDataScopeUserDept(dataScopeUserDeptDtoList) ? R.success() : R.faild();

    }

    //    @ApiOperation(value = "用户部门删除", notes = "用户部门删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody @Valid DataScopeUserDeptDelete dataScopeUserDeptDelete) throws DtoNullException {
        return iDataScopeUserDeptService.deleteDataScopeUserDept(dataScopeUserDeptDelete) ? R.success() : R.faild();
    }

    //    @ApiOperation(value = "用户部门修改", notes = "用户部门修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid List<DataScopeUserDeptDtoEdit> dataScopeUserDeptDtoEditList) throws DtoNullException {

        return iDataScopeUserDeptService.updateDataScopeUserDept(dataScopeUserDeptDtoEditList) ? R.success() : R.faild();

    }

    @ApiOperation(value = "用户ID查询用户部门(数据权限)", notes = "用户ID查询用户部门(数据权限)")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Long userId) throws DtoNullException {

        return R.success(iDataScopeUserDeptService.queryDataScopeUserDeptVoById(userId));

    }

}

